<script setup lang="ts">
import { ref, onMounted } from "vue";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import ReCol from "@/components/ReCol";
const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    title: "",
    status: 0
  })
});
const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}
defineExpose({ getRef });

const dataPermissionOptions = ref([
	{
		id: 1,
		name: '启用'
	},
	{
		id: 2,
		name: '不启用'
	}
])
const menuListTree = ref()
const currentChange = (data, check, node) => {
	let arr = [...menuListTree.value.getCheckedKeys(),...menuListTree.value.getHalfCheckedKeys()]
	newFormInline.value.parentArr = arr
}
const checkStrictly = ref(true)
onMounted(()=> {
	checkStrictly.value = false
})
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="auto"
  >
    <el-row :gutter="30">
      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="角色名称" prop="name">
          <el-input
            v-model="newFormInline.name"
            clearable
            placeholder="请输入角色名称"
          />
        </el-form-item>
      </re-col>

	  <re-col :value="24" :xs="24" :sm="24">
	    <!-- <el-form-item label="菜单" prop="menuIds">
	      <el-select
	        v-model="newFormInline.menuIds"
	        placeholder="请选择菜单"
	        class="w-full"
	        clearable
			multiple
	      >
	        <el-option
	          v-for="(item, index) in newFormInline.menuIdsOptions"
	          :key="index"
	          :label="item.name"
	          :value="item.menuId"
	        />
	      </el-select>
	    </el-form-item> -->
		<!-- <el-form-item label="角色菜单" prop="menuIds">
		  <el-cascader
			v-model="newFormInline.menuIds"
			class="w-full"
			:options="newFormInline.menuIdsOptions"
			:props="{
			  value: 'menuId',
			  label: 'name',
			  checkStrictly: false,
			  multiple: true
			}"
			clearable
			filterable
			placeholder="请选择角色菜单"
		  >
			<template #default="{ node, data }">
			  <span>{{ data.name }}</span>
			  <span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
			</template>
		  </el-cascader>
		</el-form-item> -->
	  </re-col>
	  <re-col :value="24" :xs="24" :sm="24">
		<el-form-item label="角色菜单" prop="menuIds">
      <div  style="max-height: 500px;overflow: auto; width: 100%;">
        <el-tree
          ref="menuListTree"
          :data="newFormInline.menuIdsOptions"
          :default-checked-keys="newFormInline.menuIds"
          show-checkbox
          default-expand-all
          node-key="menuId"
          highlight-current
          :check-strictly="checkStrictly"
          @check="currentChange"
           v-if="newFormInline.menuIdsOptions && newFormInline.menuIdsOptions.length > 0"
          :props="{
        	  value: 'menuId',
        	  label: 'name',
        	  multiple: true
          }"
        >
        </el-tree>
        <div v-else style="color: #909399;">暂无数据</div>
      </div>

		</el-form-item>
	  </re-col>
	  <re-col :value="24" :xs="24" :sm="24">
	    <el-form-item label="数据权限" prop="dataPermission">
	      <el-select
	        v-model="newFormInline.dataPermission"
	        placeholder="请选择数据权限"
	        class="w-full"
	        clearable
	      >
	        <el-option
	          v-for="(item, index) in dataPermissionOptions"
	          :key="index"
	          :label="item.name"
	          :value="item.id"
	        />
	      </el-select>
	    </el-form-item>
	  </re-col>
	  <re-col :value="24" :xs="24" :sm="24">
	    <el-form-item label="备注" prop="remarks">
	      <el-input
	        v-model="newFormInline.remarks"
	        clearable
	        placeholder="请输入备注"
          type="textarea"
          :rows="3"
	      />
	    </el-form-item>
	  </re-col>
    </el-row>
  </el-form>
</template>
<style scoped>
.avatar-uploader .el-upload {
  border: 1px dashed var(--el-border-color);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--el-transition-duration-fast);
}

.avatar-uploader .el-upload:hover {
  border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  text-align: center;
}
</style>
